package uk.ac.bath.machines.bool;


import java.util.Enumeration;
import java.util.Vector;
import uk.ac.bath.environment.MachineIF;
import uk.ac.bath.util.Tweakable;

import uk.ac.bath.legacy.RecursiveMachine;
import uk.ac.bath.legacy.MappedOperator;
import uk.ac.bath.legacy.PalleteIF;
import uk.ac.bath.util.MyRandom;
import uk.ac.bath.util.TweakableDouble;

public class LogicalMachine extends RecursiveMachine {

  //  final static public Value protoValue = new Value(0.0);
  
    public static Vector<Tweakable> tweaks = new Vector<Tweakable>();
    public static TweakableDouble maxValue = new TweakableDouble(tweaks, 0.0, 100.0, 2.0, 1.0, "MaxValue");
 

    public LogicalMachine(Vector<MappedOperator> unitList) {
        super(unitList,Palettes.full);
    }

    public LogicalMachine(int nOps, PalleteIF pallete) {
        super(nOps,Palettes.full);

    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        Vector<MappedOperator> newList = new Vector<MappedOperator>(size);
        for (Enumeration e = unitList.elements(); e.hasMoreElements();) {
            MappedOperator o = (MappedOperator) (((MappedOperator) (e.nextElement())).clone());
            newList.add(o);
        }
        return new LogicalMachine(newList);
    }


  

   
    public LogicalMachine splice(MachineIF bx) throws CloneNotSupportedException {

        LogicalMachine a=this;
        LogicalMachine b=(LogicalMachine)bx;

        LogicalMachine head;
        LogicalMachine tail;

        if (a.size() > b.size()) {
            head = b;
            tail = a;
        } else {
            head = a;
            tail = b;
        }

        int crossPoint = MyRandom.nextInt(head.size());
        int sizeX = tail.size();

        Vector<MappedOperator> opList = new Vector<MappedOperator>(sizeX);
        for (int i = 0; i < sizeX; i++) {
            if (i < crossPoint) {
                opList.add(head.cloneOpAt(i));
            } else {
                opList.add(tail.cloneOpAt(i));
            }
        }


        LogicalMachine machine = new LogicalMachine(opList);

        return machine;

    }

    public int sizeIn() {
        return size;
    }

    public int sizeOut() {
        return size;
    }

    public String parametersToString() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

//    public boolean isOn(int i) {
//        return
//    }
//
//    public float out(int i) {
//        throw new UnsupportedOperationException("Not supported yet.");
//    }

  
}
